home *** CD-ROM | disk | FTP | other *** search
/ Aminet 50 / Aminet 50 (2002)(GTI - Schatztruhe)[!][Aug 2002].iso / Aminet / dev / e / AP-examples.lha / AP-examples / AP-ToolsPrefs.e < prev    next >
Encoding:
Text File  |  2002-04-25  |  6.7 KB  |  181 lines

  1.  
  2. /* Example of using AWNPipe to create a reaction gui in E, by Dave Norris */
  3.  
  4. -> MODULE  none needed
  5.  
  6. DEF pipefile,instring[10]:LIST,
  7.     menulist,edmenugad,newgad,deletegad,insertgad,close,strtotal,
  8.     menugad,subgad,bargad,akeygad,notegad,
  9.     hotkeygad,comlist,edcomgad,stackgad,addgad,deletegad2,insertgad2,wbcligad,
  10.     savegad,filereqgad,cancelgad,menu1,menu2,
  11.     in0[100]:STRING,in1[100]:STRING,in2[100]:STRING,in3[100]:STRING,in4[100]:STRING,
  12.     in5[100]:STRING,in6[100]:STRING,in7[100]:STRING,in8[100]:STRING,in9[100]:STRING,
  13.     str_spaces[10]:ARRAY OF INT
  14.  
  15. PROC main()
  16.   close:=FALSE
  17.   setdefaults()
  18.   buildgui()
  19.   WHILE close=FALSE
  20.     getline()
  21.     IF StrCmp('app',in0)
  22.       PrintF('You dropped this icon on me!\n \s\n\n',in1)
  23.     ELSEIF StrCmp('gadget',in0)
  24.       dogad()
  25.     ELSEIF StrCmp('menu',in0)
  26.       PrintF('You picked a menu item!\n\n')
  27.     ELSEIF StrCmp('close',in0)
  28.       close:=TRUE
  29.     ENDIF
  30.   ENDWHILE
  31.   Close(pipefile)
  32.   PrintF('file closed,\nsee you later.\n')
  33. ENDPROC
  34.  
  35. PROC dogad()
  36.   DEF x
  37.   x:=Val(in1)
  38.   SELECT x
  39.     CASE menulist;      PrintF('just clicked on menulist!\n\n')
  40.     CASE edmenugad;     printstring()        -> check string gads for spaces
  41.     CASE newgad;        PrintF('just pressed new!\n\n')
  42.     CASE deletegad;     PrintF('just pressed delete!\n\n')
  43.     CASE insertgad;     PrintF('just pressed insert!\n\n')
  44.     CASE menugad;       PrintF('just checked menu!\n\n')
  45.     CASE subgad;        PrintF('just checked sub!\n\n')
  46.     CASE bargad;        PrintF('just pressed bar!\n\n')
  47.     CASE akeygad;       printstring()
  48.     CASE notegad;       printstring()
  49.     CASE hotkeygad;     printstring()
  50.     CASE comlist;       PrintF('just clicked on command list!\n\n')
  51.     CASE edcomgad;      printstring()
  52.     CASE stackgad;      printstring()
  53.     CASE addgad;        PrintF('just pressed add!\n\n')
  54.     CASE deletegad2;    PrintF('just pressed delete button 2!\n\n')
  55.     CASE insertgad2;    PrintF('just pressed insert button 2!\n\n')
  56.     CASE wbcligad;      PrintF('just pressed chooser gadget!\n\n')
  57.     CASE savegad;       PrintF('just pressed save!\n\n')
  58.     CASE filereqgad;    PrintF('file selected=\s\n\n',in3)
  59.     CASE cancelgad;     PrintF('just pressed cancel!\n\n')
  60.     DEFAULT;            PrintF('You have not put me in yet!!!\n\n')
  61.   ENDSELECT
  62. ENDPROC
  63.  
  64. PROC printstring()
  65.   joinstr(); PrintF('just pressed return \q\s\q!\n\n',in2)
  66. ENDPROC
  67.  
  68. PROC joinstr()  -> glues string back together with spaces
  69.   DEF x,y
  70.   FOR x:=3 TO strtotal
  71.     FOR y:=0 TO str_spaces[x] DO StrAdd(in2,' ')
  72.     StrAdd(in2,instring[x])
  73.   ENDFOR
  74. ENDPROC
  75.  
  76. PROC buildgui()
  77.   pipefile:=Open('awnpipe:test1/xc',OLDFILE)  ->wcon:300//200/200/PipeEvents
  78.   topipe(pipefile,' " Workbench Menu Prefs 1.0 " cg dg db si so a cs app\n')
  79.  
  80.   topipe(pipefile,' layout v\n')
  81.     topipe(pipefile,' layout b 0 si\n')  ->so
  82.       topipe(pipefile,' layout b 0 so si v\n')
  83.         topipe(pipefile,' layout gt "Menu Items" b 3 so si v\n') -> 3 4 5 7 8 9
  84.           menulist:=topipe(pipefile,'listbrowser minw 180  minh 110\n')
  85.           edmenugad:=topipe(pipefile,'string lj\n')
  86.           topipe(pipefile,' layout b 0 si even\n')
  87.             newgad:=topipe(pipefile,'button gt _New\n')
  88.             deletegad:=topipe(pipefile,'button gt Delete\n')
  89.             insertgad:=topipe(pipefile,'button gt Insert\n')
  90.           topipe(pipefile,' le\n')
  91.         topipe(pipefile,' le\n')
  92.       topipe(pipefile,' le\n')
  93.       topipe(pipefile,' layout b 0 so si v\n')
  94.         topipe(pipefile,'space\n')
  95.         menugad:=topipe(pipefile,'checkbox gt _Menu\n')
  96.         subgad:=topipe(pipefile,'checkbox gt _Sub\n')
  97.         bargad:=topipe(pipefile,'button gt Bar\n')
  98.         topipe(pipefile,'space\n')
  99.         topipe(pipefile,' layout gt AmiKey b 0 so si v\n')
  100.           akeygad:=topipe(pipefile,'string minc=0 maxc=2 lj\n')
  101.         topipe(pipefile,' le\n')
  102.         topipe(pipefile,' layout gt Comment b 0 so si v\n')
  103.           notegad:=topipe(pipefile,'string minc=0 maxc=15 lj\n')
  104.         topipe(pipefile,' le\n')
  105.         topipe(pipefile,'space\n')
  106.         topipe(pipefile,'space\n')
  107.       topipe(pipefile,' le\n')
  108.       topipe(pipefile,' layout b 0 so si v\n')
  109.         topipe(pipefile,' layout gt "Hot Key" b 3 so si v\n')
  110.           hotkeygad:=topipe(pipefile,'string lj\n')
  111.         topipe(pipefile,' le\n')
  112.         topipe(pipefile,' layout gt Commands b=3 so si v\n')
  113.           comlist:=topipe(pipefile,'listbrowser minw 180  minh=70\n')
  114.           topipe(pipefile,' layout b 0 si\n')
  115.             edcomgad:=topipe(pipefile,'string lj\n')
  116.             stackgad:=topipe(pipefile,'integer maxc=6 defn 4096\n')
  117.           topipe(pipefile,' le\n')
  118.           topipe(pipefile,' layout b 0 si even\n')
  119.             addgad:=topipe(pipefile,'button gt _Add\n')
  120.             deletegad2:=topipe(pipefile,'button gt Delete\n')
  121.             insertgad2:=topipe(pipefile,'button gt Insert\n')
  122.             wbcligad:=topipe(pipefile,'chooser pu cl " WB|CLI"\n')
  123.           topipe(pipefile,' le\n')
  124.         topipe(pipefile,' le\n')
  125.       topipe(pipefile,' le\n')
  126.     topipe(pipefile,' le\n')
  127.     topipe(pipefile,' layout b 0 si so\n')
  128.       savegad:=topipe(pipefile,'button gt Save\n')
  129.       topipe(pipefile,'space\n')
  130.       topipe(pipefile,'space\n')
  131.       topipe(pipefile,'space\n')
  132.       topipe(pipefile,'space\n')
  133.       cancelgad:=topipe(pipefile,'button gt Cancel c\n')
  134.     topipe(pipefile,' le\n')
  135.   topipe(pipefile,' le\n')
  136.  
  137.   menu1:=topipe(pipefile,' menu gt "Project |About|$! E with AWNpipe |$! By Dave Norris"\n')
  138.   menu2:=topipe(pipefile,' menu gt "Data|@AShow all data|Show part|$@GGood|$@LLuck"\n')
  139.   topipe(pipefile,'open\n')
  140. ENDPROC
  141.  
  142. PROC topipe(pipef,data)
  143.   DEF res,input[10]:STRING
  144.   Fputs(pipef,data)
  145.   IF ReadStr(pipef,input)<>-1     -> returns -1 if error or EOF encounted
  146.     IF StrCmp(input,'ok',2)
  147.       IF StrLen(input)>2 THEN res:=RightStr(input,input,(StrLen(input)-3))
  148.     ELSE  -> ^ only return res if gadget or menu, not needed for layout ^
  149.       PrintF('Error from \s\n',data)
  150.     ENDIF
  151.   ELSE
  152.     PrintF('Error from ReadStr(pipef,input)\n')
  153.     close:=TRUE
  154.   ENDIF
  155. ENDPROC Val(res)
  156.  
  157. PROC setdefaults()    -> put here to unclutter main()
  158.   instring:=[in0,in1,in2,in3,in4,in5,in6,in7,in8,in9]:LONG
  159. ENDPROC
  160.  
  161. PROC getline()     -> loops until all data seperated by spaces is collected
  162.   DEF space,input[1024]:STRING,x,gap
  163.   x:=0
  164.   IF ReadStr(pipefile,input)<>-1     -> returns -1 if error or EOF encounted
  165. ->    PrintF('input=\s,\n',input)
  166.     WHILE (space:=InStr(input,' '))<>-1
  167.       StrCopy(instring[x],input,space)
  168. ->      PrintF('instring[\d]=\s,\n',x,instring[x])
  169.       MidStr(input,input,space+1)
  170.       gap:=StrLen(input)
  171.       input:=TrimStr(input)
  172.       x:=x+1
  173.       str_spaces[x]:=gap-StrLen(input)
  174.     ENDWHILE
  175.     strtotal:=x
  176.     StrCopy(instring[x],input)
  177. ->    PrintF('instring[\d]=\s,\n',x,instring[x])
  178.   ENDIF
  179. ENDPROC
  180.  
  181.